package skin
{
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.text.TextFormat;

	public class ButtonSkin extends SkinBase
	{
		/**文本*/
		private var _labelDisplay:TextField;
		
		private var _style:TextFormat;
		
		private var _label:String='';
		
		public function ButtonSkin()
		{
			super();
			
			_ww = 70;
			_hh = 21;
		}
		
		override protected function initialize():void
		{
			isVector = true;
			states = [StateStatic.UP,StateStatic.OVER,StateStatic.DOWN,StateStatic.DISABLED];
		}
		
		override protected function stateChange():void
		{
			switch(currentState)
			{
				default:
				{
					break;
				}
			}
		}
		
		override protected function skinCompleted():void
		{
			_labelDisplay = new TextField();
			_labelDisplay.width = _ww;
			_labelDisplay.height = _hh;
			_labelDisplay.selectable = false;
			addChild(_labelDisplay);
			
			label = '按钮';
		}
		
		override protected function hostReady():void
		{
			hostCompent.addEventListener(MouseEvent.MOUSE_UP,upSkinHandler);
			hostCompent.addEventListener(MouseEvent.MOUSE_DOWN,downSkinHandler);
			hostCompent.addEventListener(MouseEvent.MOUSE_OVER,overSkinHandler);
			hostCompent.addEventListener(MouseEvent.MOUSE_OUT,outSkinHandler);
		}
		
		private function outSkinHandler(event:MouseEvent):void
		{
			currentState = StateStatic.UP;
		}
		
		private function overSkinHandler(event:MouseEvent):void
		{
			currentState = StateStatic.OVER;
		}
		
		private function downSkinHandler(event:MouseEvent):void
		{
			currentState = StateStatic.DOWN;
		}
		
		private function upSkinHandler(event:MouseEvent):void
		{
			currentState = StateStatic.UP;
		}
		
		override protected function createSkin(stateName:String, container:Sprite):void
		{
			switch(stateName)
			{
				case StateStatic.UP:
				{
					container.graphics.beginFill(0x696969);
					container.graphics.drawRoundRect(0,0,_ww,_hh,10);
					container.graphics.endFill();
					break;
				}
				case StateStatic.DOWN:
				{
					container.graphics.beginFill(0x969696);
					container.graphics.drawRoundRect(0,0,_ww,_hh,10);
					container.graphics.endFill();
					break;
				}
				case StateStatic.OVER:
				{
					container.graphics.beginFill(0x787878);
					container.graphics.drawRoundRect(0,0,_ww,_hh,10);
					container.graphics.endFill();
					break;
				}
				case StateStatic.DISABLED:
				{
					container.graphics.beginFill(0xc3c3c3);
					container.graphics.drawRoundRect(0,0,_ww,_hh,10);
					container.graphics.endFill();
					break;
				}
			}
		}
		
		/**标签*/
		public function set label(text:String):void
		{
			if(_label != text)
			{
				_label = text;
				_labelDisplay.text = _label;
			}
		}
		public function get label():String
		{
			return _label;
		}
		
		
		/**标签样式*/
		public function set style(textformat:TextFormat):void
		{
			if(_style != textformat)
			{
				_style = textformat;
				
				_labelDisplay.defaultTextFormat = _style;
				_labelDisplay.text = _label;
			}
		}
		public function get style():TextFormat
		{
			return _style;
		}
		
		
	}
}